package br.cefetpe.tsi.game.desktop.ui.gui;

import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

public class Game extends JFrame {

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;

	private JMenuBar jmbRoulletteBar = null;

	private JMenu jmFile = null;

	private JMenu jmHelp = null;

	private RoullettePanel rPanel = null;

	private JMenu jmGame = null;

	private JMenuItem jmiOpenGame = null;

	private JMenuItem jmiSaveGame = null;

	private JMenuItem jmiExit = null;

	private JMenuItem jmiScramble = null;

	private JMenuItem jmiSolve = null;

	private JMenuItem jmiUserHelp = null;

	private JMenuItem jmiAbout = null;
	
	/**
	 * This is the default constructor
	 */
	public Game() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(510, 500);
		this.setResizable(false);
		this.setJMenuBar(getJmbRoulletteBar());
		this.setContentPane(getJContentPane());
		this.setTitle("-=::Carrossel de Cores ::=-");
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getRPanel(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jmbRoulletteBar	
	 * 	
	 * @return javax.swing.JMenuBar	
	 */
	private JMenuBar getJmbRoulletteBar() {
		if (jmbRoulletteBar == null) {
			jmbRoulletteBar = new JMenuBar();
			jmbRoulletteBar.add(getJmFile());
			jmbRoulletteBar.add(getJmGame());
			jmbRoulletteBar.add(getJmHelp());
		}
		return jmbRoulletteBar;
	}

	/**
	 * This method initializes jmFile	
	 * 	
	 * @return javax.swing.JMenu	
	 */
	private JMenu getJmFile() {
		if (jmFile == null) {
			jmFile = new JMenu();
			jmFile.setText("Arquivo");
			jmFile.add(getJmiOpenGame());
			jmFile.add(getJmiSaveGame());
			jmFile.addSeparator();
			jmFile.add(getJmiExit());
		}
		return jmFile;
	}

	/**
	 * This method initializes jmHelp	
	 * 	
	 * @return javax.swing.JMenu	
	 */
	private JMenu getJmHelp() {
		if (jmHelp == null) {
			jmHelp = new JMenu();
			jmHelp.setText("Ajuda");
			jmHelp.add(getJmiUserHelp());
			jmHelp.add(getJmiAbout());
		}
		return jmHelp;
	}

	/**
	 * This method initializes rPanel	
	 * 	
	 * @return br.cefetpe.tsi.game.desktop.ui.gui.RoullettePanel	
	 */
	private RoullettePanel getRPanel() {
		if (rPanel == null) {
			rPanel = new RoullettePanel();
			rPanel.setBounds(new Rectangle(1, 0, 500, 500));
		}
		return rPanel;
	}
	
	
	/**
	 * This method initializes jmGame	
	 * 	
	 * @return javax.swing.JMenu	
	 */
	private JMenu getJmGame() {
		if (jmGame == null) {
			jmGame = new JMenu();
			jmGame.setText("Jogo");
			jmGame.add(getJmiScramble());
			jmGame.add(getJmiSolve());
		}
		return jmGame;
	}

	/**
	 * This method initializes jmiOpenGame	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJmiOpenGame() {
		if (jmiOpenGame == null) {
			jmiOpenGame = new JMenuItem();
			jmiOpenGame.setText("Abrir Jogo...");
			jmiOpenGame.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					getRPanel().openRoullette();
				}
			});
		}
		return jmiOpenGame;
	}

	/**
	 * This method initializes jmiSaveGame	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJmiSaveGame() {
		if (jmiSaveGame == null) {
			jmiSaveGame = new JMenuItem();
			jmiSaveGame.setText("Salvar Jogo...");
			jmiSaveGame.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					getRPanel().saveRoullette();
				}
			});
		}
		return jmiSaveGame;
	}

	/**
	 * This method initializes jmiExit	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJmiExit() {
		if (jmiExit == null) {
			jmiExit = new JMenuItem();
			jmiExit.setText("Sair");
			jmiExit.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.exit(0);
				}
			});
		}
		return jmiExit;
	}

	/**
	 * This method initializes jmiScramble	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJmiScramble() {
		if (jmiScramble == null) {
			jmiScramble = new JMenuItem();
			jmiScramble.setText("Embaralhar");
			jmiScramble.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					getRPanel().scrambleRoullette();
				}
			});
		}
		return jmiScramble;
	}

	/**
	 * This method initializes jmiSolve	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJmiSolve() {
		if (jmiSolve == null) {
			jmiSolve = new JMenuItem();
			jmiSolve.setText("Resolver");
			jmiSolve.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					getRPanel().goSolving();
				}
			});
		}
		return jmiSolve;
	}

	/**
	 * This method initializes jmiUserHelp	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJmiUserHelp() {
		if (jmiUserHelp == null) {
			jmiUserHelp = new JMenuItem();
			jmiUserHelp.setText("Como Jogar...");
			jmiUserHelp.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					
				}
			});
		}
		return jmiUserHelp;
	}

	/**
	 * This method initializes jmiAbout	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJmiAbout() {
		if (jmiAbout == null) {
			jmiAbout = new JMenuItem();
			jmiAbout.setText("Sobre");
			jmiAbout.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					AboutDialog ad = new AboutDialog(null);
					ad.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
				}
			});
		}
		return jmiAbout;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				Game thisClass = new Game();
				thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				thisClass.setVisible(true);
				
			}
		});
	}
}  //  @jve:decl-index=0:visual-constraint="10,10"
